#include <iostream>
using namespace std;

// 左移运算符重载

class Person
{
    friend ostream& operator<<(ostream& cout, Person& p); // 友元

private:
    int age;
    int money;

public:
    Person(int age, int money)
    {
        this->age = age;
        this->money = money;
    }

    // 利用成员函数 重载左移运算符
    // 不会利用成员函数重载<<运算符，因为无法实现 cout在左侧
    // ostream operator<<(ostream& cout)

};

//只能利用全局函数重载左移运算符
ostream& operator<<(ostream& cout, Person& p)
{
    cout << "age = " << p.age << "\tmoney = " << p.money;
    return cout;
}

void test1()
{
    Person p(10,300);
    
    cout << p << endl;
}


// 右移运算符重载
class date
{
public:
    date(int x=0, int y=0, int z=0) {
        year=x; 
        month=y; 
        day=z; 
    }
    friend ostream& operator<<(ostream& ost, const date& d);
    
    friend istream& operator>>(istream& ist, date& d);
    
private:
    int year, month, day; 
};

ostream& operator <<(ostream& ost, const date& d) { // ost: an object of ostream class
    ost << d.year << "." << d.month<<"."<<d.day<<endl;
    return ost; 
}

istream& operator >>(istream& ist, date& d) { // ist: an object of istream class
    cout<<"please input the date, e.g., 2002 12 15："<<endl;
    ist >>d.year>>d.month>>d.day;
    return ist; 
}

void test2(){
    date d;
    cin >> d; // operator>>(cin, d)
    cout << d; // operator<<(cout, d)
    
}

int main()
{
    test1();
    cout << "=================" << endl;
    test2();
    
    return 0;
}